* Set working directory to where negotiation.do and contracts.csv is saved
clear all
set more off
cd /Users/byrned/Dropbox/Research/Negotiation/Stata/Replication  /* <-- SET THIS, THEN RUN */


*-------------- Table 1: Baseline Results -----------*

* Load data
est clear 
insheet using contracts.csv, clear 
rename date date_str
gen date=date(date_str,"DMY")
format date %td

* Regressions
reg log_bill cont_call cont_neg i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m1
reg totalbill cont_call cont_neg i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m2

* Joint test reported in the paper
test cont_call=cont_neg

* Output
local titles "& Log Bill & Bill \\"
local numbers "& (1) & (2)  \\ \midrule \\ "
local str="$str"
esttab using tab1_base.tex, replace b(3) se(3) ///
	keep(cont_call cont_neg) ///
	order(cont_call cont_neg) ///
	varlabel(cont_call "Call-In" ///
			 cont_neg "Negotiated") ///
	stats(r2_a N, labels("R-Squared" "Observations") fmt(%12.3f %12.0f)) ///
	starl($^{*}$ .1 $^{**}$ .05 $^{***}$ .01) ///	
	mlabels(none) nonumbers posthead("`titles'" "`numbers'") ///
	booktabs nonote sty(tex)	
est clear



*-------- Table 2: Information Revelation and Negotiated Price Offers ---------*

* Interactions
gen cont_call_new=cont_call*(1-stage1_switch)
gen cont_neg_new=cont_neg*(1-stage1_switch)
gen cont_neg_new_low=cont_neg*(1-stage1_switch)*stage2_ref_low
gen cont_call_switch=cont_call*stage1_switch
gen cont_neg_switch=cont_neg*stage1_switch
gen cont_neg_switch_low=cont_neg*stage1_switch*stage2_ref_low
gen cont_neg_low=cont_neg*stage2_ref_low

* Regressions
qui reg log_bill cont_call cont_neg i.retailer, cluster(callid)
eststo m0

qui reg log_bill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m1

qui reg log_bill cont_call cont_call_switch ///
			 cont_neg cont_neg_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m2

qui reg log_bill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch cont_neg_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m3

* Test results comparing search and switching costs cited in the paper
test cont_call_switch=cont_neg_switch

qui reg log_bill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m4


* Add to Output
local title1 " & \multicolumn{5}{c}{Log Bill}\\"
local title2 " \cmidrule(lr){2-6}"
local numbers " & (1) & (2) & (3) & (4) & (5)  \\ \midrule \\"
local str="$str"
esttab using tab2_barg.tex, replace b(3) se(3) ///
	keep(cont_call cont_call_switch cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low) ///
	order(cont_call cont_call_switch cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low) ///
	varlabel(cont_call "Call-In" ///
			 cont_call_switch "Call-In $\times$ Switcher" ///
			 cont_neg "Negotiated" ///
			 cont_neg_switch "Negotiated $\times$ Switcher" ///
			 cont_neg_low "Negotiated $\times$ Low Res. Price" ///
			 cont_neg_switch_low "Negotiated $\times$ Switcher $\times$ Low Res. Price") ///
	stats(r2_a N, labels("R-Squared" "Observations") fmt(%12.3f %12.0f)) ///
	starl($^{*}$ .1 $^{**}$ .05 $^{***}$ .01) ///
	nonote nomtitles booktabs nonumber posthead("`title1'" "`title2'" "`numbers'")	
est clear
	

* Regressions
qui reg totalbill cont_call cont_neg i.retailer, cluster(callid)
eststo m0

qui reg totalbill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m1

qui reg totalbill cont_call cont_call_switch ///
			 cont_neg cont_neg_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m2

qui reg totalbill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch cont_neg_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m3

* Test results comparing search and switching costs cited in the paper
test cont_call_switch=cont_neg_switch

qui reg totalbill cont_call cont_call_switch ///
			 cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low ///
			 i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m4


* Add to Output
local title1 " & \multicolumn{5}{c}{Bill}\\"
local title2 " \cmidrule(lr){2-6}"
local numbers " & (1) & (2) & (3) & (4) & (5)  \\ \midrule \\"
local str="$str"	
esttab using tab2_barg.tex, append b(2) se(2) ///
	keep(cont_call cont_call_switch cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low) ///
	order(cont_call cont_call_switch cont_neg cont_neg_switch cont_neg_low cont_neg_switch_low) ///
	varlabel(cont_call "Call-In" ///
			 cont_call_switch "Call-In $\times$ Switcher" ///
			 cont_neg "Negotiated" ///
			 cont_neg_switch "Negotiated $\times$ Switcher" ///
			 cont_neg_low "Negotiated $\times$ Low Res. Price" ///
			 cont_neg_switch_low "Negotiated $\times$ Switcher $\times$ Low Res. Price") ///
	stats(r2_a N, labels("R-Squared" "Observations") fmt(%12.3f %12.0f)) ///
	starl($^{*}$ .1 $^{**}$ .05 $^{***}$ .01) ///
	nonote nomtitles booktabs nonumber posthead("`title1'" "`title2'" "`numbers'")
est clear



*----- Table 3: Subsidy Status and Targeted Discrimination in Negotiations -----*

* Interactions
gen cont_call_subs=cont_call*stage1_subs
gen cont_neg_subs=cont_neg*stage1_subs


* Regression in logs
qui reg log_bill cont_call cont_call_subs cont_neg cont_neg_subs i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m1

* Regression in levels
qui reg totalbill cont_call cont_call_subs cont_neg cont_neg_subs i.retailer i.caller i.date exper exper_sq, cluster(callid)
eststo m2

* Regression Output
local title1 " & Log Bill & Bill\\"
local numbers " & (1) & (2) \\ \midrule \\"
local str="$str"
esttab using tab3_subsidy.tex, replace b(3) se(3) ///
	keep(cont_call cont_call_subs cont_neg cont_neg_subs) ///
	order(cont_call cont_call_subs cont_neg cont_neg_subs) ///
	varlabel(cont_call "Call-In" ///
			 cont_call_subs "Call-In $\times$ Subsidy" ///
			 cont_neg "Negotiated" ///
			 cont_neg_subs "Negotiated $\times$ Subsidy") ///	
	stats(r2_a N, labels("R-Squared" "Observations") fmt(%12.3f %12.0f)) ///			 
	starl($^{*}$ .1 $^{**}$ .05 $^{***}$ .01) ///
	nonote nomtitles booktabs nonumber posthead("`title1'" "`title2'" "`numbers'") 
est clear



*------------------- Figure 2: Distribution of Annual Bills -------------------*
*---------- Associated With Posted, Call-In, and Negotiated Contracts ---------*

gen lowprice=900
gen highprice=970
gen dens=0 if _n==1
qui replace dens=dens[_n-1]+0.0001 if _n>1

twoway	(kdensity totalbill if cont==2 & totalbill>=800 & totalbill<=1400, lcolor(navy) lwidth(medthick)) ///
		(kdensity totalbill if cont==3 & totalbill>=800 & totalbill<=1400, lcolor(cranberry) lwidth(medthick) lpattern(dash) ) ///
		(kdensity totalbill if cont==4 & totalbill>=800 & totalbill<=1400, lcolor(green) lwidth(medthick) lpattern(shortdash)) ///
		(line dens lowprice if dens<=0.00965, lcolor(black) lpattern(shortdash) lwidth(*0.75)) ///
		(line dens highprice if dens<=0.00965, lcolor(black) lpattern(shortdash) lwidth(*0.75) ///
		legend(order (1 2 3 4) rows(4) ring(0) size(*0.8) region(lwidth(*0.0)) symx(*0.5) position(1) rowgap(*1) ///
		label(1 "Posted Price") label(2 "Call-In Price") ///
		label(3 "Negotiated Price") label(4 "Reference Price")) ///
		xlabel(800(100)1400) ylabel(0(0.002)0.01) ///
		xtitle("Total Annual Bill ($)") ytitle("Density") plotregion(style(none)) ///
		text(0.01 900 "Low" "Price" "($900)", size(*0.65) color(gs0)) ///		
		text(0.01 970 "High" "Price" "($970)", size(*0.65) color(gs0)))	
graph export fig2_billdist.pdf, as(pdf) replace



*----------------- Figure 3: Cumulative Distribution of Annual Bills ----------*
*--------------------------Among Incumbents and Entrants ----------------------*

cumul totalbill if incumb==1 & cont==3, gen(ecbig) equal
cumul totalbill if incumb==0 & cont==3, gen(ecsmall) equal
twoway 	(line ecbig totalbill if totalbill>=800 & totalbill<=1400, connect(stairstep) sort lcolor(navy) lwidth(medthick)) ///
		(line ecsmall totalbill if totalbill>=800 & totalbill<=1400, connect(stairstep) sort lcolor(cranberry) lwidth(medthick) lpattern(dash) ///
		xlabel(800(100)1400) ///
		legend(order (1 2) rows(2) ring(0) size(*0.8) region(lwidth(*0.0)) symx(*0.5) position(11) rowgap(*1) ///
		label(1 "Incumbents") label(2 "Entrants")) ///
		xtitle("Total Annual Bill ($)") ytitle("Cumulative Density") plotregion(style(none))) 
graph export fig3_billdistfirm.pdf, as(pdf) replace

	
